package com.upsuns.pbio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.upsuns.util.IOUtil;

/**
 *@Description:<p>TimeServer实现，基于伪异步IO模型</p>
 *@author 王旭
 *@time 2016年3月16日 下午9:51:33
 */
public class TimeServer {
	
	private ServerSocket server;
	
	public TimeServer(int port) throws IOException {
		server = new ServerSocket(port);
		System.out.println("服务器已开启，监听端口为：" + port);
	}
	
	public void doServer() {
		
		TimeServerExecutePool pool = new TimeServerExecutePool(50, 10000);
		Socket socket = null;
		try {
			while(true) {
				socket = server.accept();
				pool.execute(new TimeServerHandler(socket));
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtil.close(server);
		}
	}

}
